﻿namespace Chain.IDAL
{
    using Chain.DBUtility;
    using Chain.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class SmallChangeLog
    {
        public DataSet GetList(string strWhere)
        {

            StringBuilder builder = new StringBuilder();
            builder.Append("select *");
            builder.Append(" FROM SmallChangeLog ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(builder.ToString());

        }
        public int Add(Chain.Model.SmallChangeLog model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into SmallChangeLog(");
            builder.Append("SmallChangeMemID,SmallChangeNumber,SmallChangeChangeType,SmallChangeRemark,SmallChangeShopID,SmallChangeCreateTime,SmallChangeUserID,SmallChangeOrderCode,SmallChangeGiveMemID)");
            builder.Append(" values (");
            builder.Append("@SmallChangeMemID,@SmallChangeNumber,@SmallChangeChangeType,@SmallChangeRemark,@SmallChangeShopID,@SmallChangeCreateTime,@SmallChangeUserID,@SmallChangeOrderCode,@SmallChangeGiveMemID)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] {
                new SqlParameter("@SmallChangeMemID", SqlDbType.Int, 4),
                new SqlParameter("@SmallChangeNumber", SqlDbType.Money, 8),
                new SqlParameter("@SmallChangeChangeType", SqlDbType.Int, 1),
                new SqlParameter("@SmallChangeRemark", SqlDbType.NVarChar, 200),
                new SqlParameter("@SmallChangeShopID", SqlDbType.Int, 4),
                new SqlParameter("@SmallChangeCreateTime", SqlDbType.DateTime),
                new SqlParameter("@SmallChangeUserID", SqlDbType.Int, 4),
                new SqlParameter("@SmallChangeOrderCode", SqlDbType.NVarChar, 200),
                new SqlParameter("@SmallChangeGiveMemID", SqlDbType.Int) };
            cmdParms[0].Value = model.SmallChangeMemID;
            cmdParms[1].Value = model.SmallChangeNumber;
            cmdParms[2].Value = model.SmallChangeChangeType;
            cmdParms[3].Value = model.SmallChangeRemark;
            cmdParms[4].Value = model.SmallChangeShopID;
            cmdParms[5].Value = model.SmallChangeCreateTime;
            cmdParms[6].Value = model.SmallChangeUserID;
            cmdParms[7].Value = model.SmallChangeOrderCode;
            cmdParms[8].Value = model.SmallChangeGiveMemID;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }
    }
}

